/***
 * * PROJECT
 * *    ATaG
 * * VERSION
 * *    $Revision: 1.4 $
 * * DATE
 * *    $Date: 2007/06/17 11:09:01 $
 * * LOG
 * *    $Log: NodeLocation.java,v $
 * *    Revision 1.4  2007/06/17 11:09:01  animesh
 * *    Serialization done. New Sensor and Actuator classes added.
 * *
 * *    Revision 1.3  2007/06/13 00:43:31  animesh
 * *    no message
 * *
 * *    Revision 1.2  2007/06/09 07:15:52  animesh
 * *    update after fixing all but sets and serialization.
 * *
 * *    Revision 1.5  2006/12/14 23:49:06  lmottola
 * *    Added serialVersionUID.
 * *
 * *    Revision 1.4  2006/12/14 23:48:29  lmottola
 * *    Bug fix for Math class.
 * *
 * *    Revision 1.3  2006/12/13 11:59:54  animesh
 * *    added method for computing distance.
 * *
 * *    Revision 1.2  2006/10/19 21:21:52  lmottola
 * *    Added CVS preamble.
 * *
 * *
 * *   ATaG (Abstract Task Graph) - Data-driven Macroprogramming for
 * *                                Sensor Networks
 * *
 * *   This program is free software; you can redistribute it and/or
 * *   modify it under the terms of the GNU General Public License
 * *   as published by the Free Software Foundation; either version 2
 * *   of the License, or (at your option) any later version.
 * *
 * *   This program is distributed in the hope that it will be useful,
 * *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 * *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * *   GNU General Public License for more details.
 * *
 * *   You should have received a copy of the GNU General Public License
 * *   along with this program; if not, you may find a copy at the FSF web
 * *   site at 'www.gnu.org' or 'www.fsf.org', or you may write to the
 * *   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * *   Boston, MA  02111-1307, USA
 ***/

package atag.runtime;

//import java.io.Serializable;
import atag.j2mespecific.Serializable;
import atag.j2mespecific.Cloneable;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.IOException;

/**
 * The class for the node location. Maybe later, the coordinates themselves
 * should be cast [from float or int or whatever]
 *
 * @author Animesh
 */
public class NodeLocation implements Cloneable, Serializable {
    
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    
    /**
     * X coordinate
     */
    float x;
    
    /**
     * Y coordinate
     */
    float y;
    
    /**
     * Creates a new instance of NodeLocation
     */
    public NodeLocation() {
    }
    
    /**
     * Creates a new instance of NodeLocation
     */
    public NodeLocation(float argX, float argY) {
        x = argX;
        y = argY;
    }
    
    /**
     * Set the value of X
     */
    public void setX(float argX) {
        x = argX;
    }
    
    /**
     * Set the value of Y
     */
    public void setY(float argY) {
        y = argY;
    }
    
    /**
     * Gets the value of X
     */
    public float getX() {
        return x;
    }
    
    /**
     * Gets the value of Y
     */
    public float getY() {
        return y;
    }
    
//	public NodeLocation clone() {
    public Object clone(){
        return new NodeLocation(x,y);
    }
    
    public boolean equals(NodeLocation arg_location) {
        return ((this.getX() == arg_location.getX()) && (this.getY() == arg_location
                .getY()));
    }
    
    public double distanceFrom(NodeLocation n) {
        return Math.sqrt((this.x - n.getX()) * (this.x - n.getX())
        + (this.y - n.getY()) * (this.y - n.getY()));
    }
    
    
    public void serialize(DataOutput dg) throws IOException {
        dg.writeFloat(this.x);
        dg.writeFloat(this.y);
    }
    

    
    public void deserialize(DataInput dg) throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException {
        this.x = dg.readFloat();
        this.y = dg.readFloat();
    }
}
